package info.xiao.dataStructrue.array;

import java.util.Arrays;

/**
 * @Classname ThirdMax
 * @Description 第三大的数
 * @Url https://leetcode.cn/problems/third-maximum-number/
 * @Date 2023/4/11 17:39
 * @Created by 晓龙Oba
 */
public class ThirdMax {
    public static void main(String[] args) {
        int[] nums = {3, 2, 1};
        int result = thirdMax(nums);
        System.out.println(result);
    }

    private static int thirdMax(int[] nums) {

        Arrays.sort(nums);
        nums = Arrays.stream(nums).distinct().toArray();
        return nums.length < 3 ? nums[nums.length - 1] : nums[nums.length - 3];
    }
}
